package top.alanshelby.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import top.alanshelby.entity.Item;
import top.alanshelby.service.ItemService;

import java.util.List;

@Controller
public class ItemController {

    @Autowired
    private ItemService itemService;

    @RequestMapping(value = "queryItem")
    public String queryGoods(Model model) {
        List<Item> itemList = itemService.findItemList();
        model.addAttribute("itemList", itemList);
        return "itemList";
    }

    @RequestMapping(value = "editItem")
    public String editItem(Integer id, Model model) {
        Item item = itemService.getItemById(id);
        model.addAttribute("item", item);
        return "itemEdit";
    }

    @RequestMapping(value = "getItem")
    @ResponseBody
    public Item getItem(Integer id) {
        Item item = itemService.getItemById(id);
        return item;
    }
}
